package com.yunkss.eftool.crypto.params;

import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.math.ec.custom.gm.SM2P256V1Curve;

import java.math.BigInteger;

/**
 * @author csx
 * @date 2022/2/18 8:49
 * @desc
 */

public class SM2Parameters {
    public static final SM2P256V1Curve CURVE = new SM2P256V1Curve();
    public static final BigInteger SM2_ECC_P;
    public static final BigInteger SM2_ECC_A;
    public static final BigInteger SM2_ECC_B;
    public static final BigInteger SM2_ECC_N;
    public static final BigInteger SM2_ECC_H;
    public static final BigInteger SM2_ECC_GX;
    public static final BigInteger SM2_ECC_GY;
    public static final ECPoint G_POINT;
    public static final ECDomainParameters DOMAIN_PARAMS;
    public static final int CURVE_LEN;

    public SM2Parameters() {
    }

    static {
        SM2_ECC_P = CURVE.getQ();
        SM2_ECC_A = CURVE.getA().toBigInteger();
        SM2_ECC_B = CURVE.getB().toBigInteger();
        SM2_ECC_N = CURVE.getOrder();
        SM2_ECC_H = CURVE.getCofactor();
        SM2_ECC_GX = new BigInteger("32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", 16);
        SM2_ECC_GY = new BigInteger("BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", 16);
        G_POINT = CURVE.createPoint(SM2_ECC_GX, SM2_ECC_GY);
        DOMAIN_PARAMS = new ECDomainParameters(CURVE, G_POINT, SM2_ECC_N, SM2_ECC_H);
        CURVE_LEN = ParameterCalculator.getCurveLength(DOMAIN_PARAMS);
    }
}
